package com.dukla;

import com.dukla.picbak.handler.FileScanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class Application implements CommandLineRunner {

    private final Logger logger =
            LoggerFactory.getLogger(Application.class);

    @Autowired
    FileScanner fileScanner;


    public static void main(String[] args) {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args);
        applicationContext.registerShutdownHook();
    }

    /**
     * CommandLineRunner 接口
     * 主要用于实现在应用初始化后，去执行一段代码块逻辑，这段初始化代码在整个应用生命周期内只会执行一次。
     */
    @Override
    public void run(String... args) {
        logger.info("Picture backup start...");
        fileScanner.start();
    }
}
